﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Timer = System.Windows.Forms.Timer;

namespace Ls.ImageSharep.App
{
    public partial class frmImagMain : Form
    {
        Timer  _timer  = new Timer();

        static frmImagMain _fromImagMain;

        public static frmImagMain Instance
        {
             get 
             { 
                if(_fromImagMain == null)
                {
                     _fromImagMain = new frmImagMain();
                }
                return _fromImagMain;
            }
        }

        public  Panel PnlContainer
        {
            get { return palContainer; }
            set { palContainer = value; }
        }

        public Button BackButton
        {
            get { return btnBack; }
            set { btnBack = value; }
        }

        private string? _frmCode;
        public string? FrmCode { get { return _frmCode; } set { _frmCode = value; } }

        private byte[] _templateStream;
        public  byte[] TemplateStream { get => _templateStream; set => _templateStream = value; }

       
        public frmImagMain()
        {
               
        InitializeComponent();
        }

        private void frmImagMain_Load(object sender, EventArgs e)
        {
            //this.StartPosition = FormStartPosition.;
            this.Text = "土豆Image";
            this.labdata.Text = DateTime.Now.ToString("yyyy年MM月dd日 HH时mm分ss秒");
            
            _timer.Tick += _timer_Tick;
            _timer.Interval = 1000;
            _timer.Start();

            btnBack.Visible = false;
            palimg.Visible = false;
            pallove.Visible = false;
            palcamera.Visible = false;
            _fromImagMain = this;

            FrmCode = "Home";

            UCHome uc = new UCHome();
            uc.Dock = DockStyle.Fill;
            palContainer.Controls.Add(uc);
        }

        private void _timer_Tick(object? sender, EventArgs e)
        {
            this.labdata.Text= DateTime.Now.ToString("yyyy年MM月dd日 HH时mm分ss秒");
        }

        private void btnlogout_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.Exit();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            switch (FrmCode)
            {
                case "Home":
                    palContainer.Controls["UCHome"].BringToFront();
                    break;
                case "Image":
                    palContainer.Controls["UCImage"].BringToFront();
                    break;
                case "Love":
                    palContainer.Controls["UCLove"].BringToFront();
                    break;
                case "Camera":
                    palContainer.Controls["UCCamera"].BringToFront();
                    break;
            }
           
            btnBack.Visible = false;
        }

        private void btnhome_Click(object sender, EventArgs e)
        {
            FrmCode = "Home";
            palhome.Visible = true;
            palimg.Visible = false;
            pallove.Visible = false;
            palcamera.Visible = false;
            palContainer.Controls.Clear();
            UCHome uc = new UCHome();
            uc.Dock = DockStyle.Fill;
            palContainer.Controls.Add(uc);
            btnBack.Visible = false;
        }

        private void btnImg_Click(object sender, EventArgs e)
        {
            FrmCode = "Image";
            palhome.Visible = false;
            palimg.Visible = true;
            pallove.Visible = false;
            palcamera.Visible = false;
            palContainer.Controls.Clear();
            UCImage uc = new UCImage();
            uc.Dock = DockStyle.Fill;
            palContainer.Controls.Add(uc);
            btnBack.Visible = false;
        }

        private void btnlove_Click(object sender, EventArgs e)
        {
            FrmCode = "Love";
            palhome.Visible = false;
            palimg.Visible = false;
            pallove.Visible = true;
            palcamera.Visible = false;
            palContainer.Controls.Clear();
            UCLove uc = new UCLove();
            uc.Dock = DockStyle.Fill;
            palContainer.Controls.Add(uc);
            btnBack.Visible = false;
        }

        private void btncamera_Click(object sender, EventArgs e)
        {
            FrmCode = "Camera";
            palhome.Visible = false;
            palimg.Visible = false;
            pallove.Visible = false;
            palcamera.Visible = true;
            palContainer.Controls.Clear();
            UCCamera uc = new UCCamera();
            uc.Dock = DockStyle.Fill;
            palContainer.Controls.Add(uc);
            btnBack.Visible = false;
        }
    }
}
